import Instance from "./Instance.js";

const hand = {


    update: function () {
        this.handIconMatch()
        this.handNameTextMatch()
        this.seedBagMatch()
    },

    onLayoutStart() {

        rt.addEventListener("wheel", e => this.OnMouseWheel(e, rt));
        hand.handIcon = Instance.GetPickInstance("HandIcon")
        hand.handNameText = Instance.GetPickInstance("HandTakeName")
        hand.CurrentHandTake = null;
        hand.SeedBagArray = ["ApplesSeed", "PotatoesSeed", "PineappleSeed"]
        // console.log(hand.SeedBagArray.length)
        hand.SeedBagIndex = 1


    },


    handIconMatch() {
        hand.handIcon.setAnimation(rt.globalVars.HandTake)

    },

    handNameTextMatch() {
       var handTakeName = rt.globalVars.HandTake
        var seedNumber = rt.globalVars[rt.globalVars.HandTake]

        hand.handNameText.text = handTakeName+
        "\n"+seedNumber

    },


    seedBagMatch() {
        hand.CurrentHandTake = hand.SeedBagArray[hand.SeedBagIndex]
        rt.globalVars.HandTake = hand.CurrentHandTake
        //console.log(rt.globalVars.HandTake)
    },


    OnMouseWheel(e, rt) {

        if (e.deltaY === -100) {
            // 滚轮向上
            if (hand.SeedBagIndex < hand.SeedBagArray.length - 1) {
                hand.SeedBagIndex += 1
            }
            else {
                hand.SeedBagIndex = 0
            }
        }



    }


}

export default hand